//
// Created by wyh on 2025-06-21 11:18.
//

#ifndef TEST_STL_TIME_H
#define TEST_STL_TIME_H

#include <ctime>
#include <string>
#ifdef _WIN32

#include <windows.h>

#else
#include<sys/time.h>
#include<unistd.h>
#endif


namespace wyh {
    namespace utility {
        class Time
        {
        public:
            Time();

            ~Time() = default;

            int year() const;

            int month() const;

            int day() const;

            int hour() const;

            int minute() const;

            int second() const;

            int week() const;

            void show() const;

            double seconds() const;

            double milliseconds() const;

            double operator-(const Time &other) const;

            static void sleep(int milliseconds);

            //format = "%Y-%m-%d %H:%M:%S"
            std::string format(const std::string &format) const;

        private:
            void get_local_time(struct tm *tm, const time_t *ticks);

            void get_time_of_day(struct timeval *tv);

        private:
            struct tm m_tm = {0};
            int m_sec;
            int m_usec;
        };
    } // namespace utility
} // namespace wyh
#endif //TEST_STL_TIME_H
